package com.iss.supermarket.util.List;

import javax.swing.*;
import java.util.List;

public class ListModelArray<T> extends DefaultListModel<T> {
    private List<T> list = null;
    @Override
    public int getSize() {
        if(list == null){
            return 0;
        }
        return list.size();
    }

    @Override
    public T getElementAt(int index) {
        if(list == null || list.size() <= index ){
            return null;
        }
        return list.get(index);
    }

    public void setList(List<T> list) {
        this.list = list;
    }
    public void addList(T obj){
        this.list.add(obj);
    }

    public List<T> getList() {
        return list;
    }

    public void clearList(){
        list.clear();
    }
}
